package com.denso.store.admin;

import com.denso.store.admin.administrator.AdminService;
import com.denso.store.common.model.Admin;
import com.jfinal.core.Controller;

/**
 * Created by lijian on 2017/12/12.
 */
public class LoginController extends Controller {

    private AdminService service = new AdminService();

    public void index() {
        Admin admin = getSessionAttr("admin");
        if(admin == null) {
            render("login.html");
        } else {
            forwardAction("/admin/scheduler/index");
        }
    }

    public void login() {
        // 0-guard 1-operator 2-store
        int type = getParaToInt("type");
        String name = getPara("name");
        String password = getPara("password");

        Admin admin = service.login(type, name, password);
        if(admin == null) {
            setAttr("notice", "管理员身份认证失败,请重新输入");
            render("login.html");
        } else {
            setSessionAttr("admin", admin.getName());
            forwardAction("/admin/scheduler/index");
        }
    }
}
